
import datetime as dt
def check_label_merge_split(infofilename,label):

    ff=open(infofilename,'r')
    infos=ff.readlines()


    merge_from=[]
    merge_to=[]
    split_from=[]
    split_to=[]
    label_state=[]
    split_from_time=[]
    split_to_time=[]
    merge_from_time = []
    merge_to_time = []
    for info in infos:
        # f_mergeto=0
        # f_mergefrom=0
        # f_splitto=0
        # f_splitfrom=0
        tmp = info.strip().split(' ')
        if label==tmp[1] and ' merge into' in info:
            merge_to.append(tmp[4])
            merge_to_time.append(tmp[0])
            # f_mergeto=1
        if 'merge into 'in info and label==tmp[4]:
            merge_from.append(tmp[1])
            merge_from_time.append(tmp[0])
            # f_mergefrom=1
        if label == tmp[1] and ' split into' in info:
            split_to.append(tmp[4])
            split_to_time.append(tmp[0])
            # f_splitto=1
        if 'split into ' in info and label == tmp[4]:
            split_from.append(tmp[1])
            split_from_time.append(tmp[0])
            # f_splitfrom=1

        # if f_mergeto==1 or f_mergefrom==1 or f_splitto==1 or f_splitfrom==1:
        #     label_state.append(info)



    # real_from=set(merge_from) | set (split_from)
    # real_to=set(merge_to) | set(split_to)
    # jiaoji=real_from & real_to
    # real_from=real_from-jiaoji
    # real_to=real_to-jiaoji


    return split_from,split_to,merge_from,merge_to,split_from_time,split_to_time,merge_from_time,merge_to_time



def get_previous_time_multimin(timefloat,interval=1):

    timestr=str(int(timefloat))
    time=dt.datetime.strptime(timestr,'%Y%m%d%H%M%S')
    pretime=(time-dt.timedelta(minutes=interval)).strftime('%Y%m%d%H%M%S')
    return float(pretime)





